/**
 * 
 */
package com.rs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rs.dao.ZhAttendanceMapper;
//import com.rs.dao.ZhAttendanceRulesMapper;
//import com.rs.dao.ZhUserMapper;
import com.rs.model.ZhAttendance;
//import com.rs.model.ZhAttendanceRules;
import com.rs.model.ZhUser;
import com.rs.service.ZhAttendanceService;
import com.rs.util.DateFormatUtil;

/**
 * 
 * @author zjw
 *
 */
@Service
@SuppressWarnings("all")
public class ZhAttendanceServiceImpl implements ZhAttendanceService {

	@Autowired
	private ZhAttendanceMapper attendancemap;
//	@Autowired
//	private ZhUserMapper um;
//	@Autowired
//	private ZhAttendanceRulesMapper arm;
	
	@Override
	public void attendanceAdd1() {
		
		int at_amtype = 0;
		int at_noontype = 0;
		int at_pmtype = 0;
		int at_nighttype = 0;
		//查看打卡规则
//		ZhAttendanceRules ra = arm.rarSelectAll();
//		//为打卡状态赋值
//		if(ra.getAtru_am().equals("No clock in")){
//			at_amtype = -1;
//		}
//		if(ra.getAtru_noon().equals("No clock in")){
//			at_noontype = -1;
//		}
//		if(ra.getAtru_pm().equals("No clock in")){
//			at_pmtype = -1;
//		}
//		if(ra.getAtru_night().equals("No clock in")){
//			at_nighttype = -1;
//		}
		ZhAttendance aa = new ZhAttendance();
		aa.setAt_amtype(at_amtype);
		aa.setAt_noontype(at_noontype);
		aa.setAt_pmtype(at_pmtype);
		aa.setAt_nighttype(at_nighttype);
////		List<ZhUser> ll = um.selectByType();
//		List<ZhAttendance> l1 = attendancemap.selectByDay();
//		if(null!=l1) {
//			for(ZhUser u1:ll) {
//				int uid = u1.getuUid();
//				for(ZhAttendance a1:l1){
//					int u_id = a1.getAt_uid();
//					if(uid==u_id) {
//						ll.remove(u1);
//					}
//				}
//			}
//		}
//		for(ZhUser uu:ll) {
//			int at_uid = uu.getuUid();
//			aa.setAt_uid(at_uid);
//			attendancemap.attendanceAdd(aa);
//		}
		
	}

	@Override
	public void attendanceUpDate(ZhAttendance attendance) {
		
		attendancemap.attendanceUpDate(attendance);
	}

	@Override
	public PageInfo<ZhAttendance> attendanceSelectAll(ZhAttendance attendance) {

		PageHelper.startPage(attendance.getPageNum(), 10);
		List<ZhAttendance> list = attendancemap.attendanceSelectAll(attendance);	
		for(ZhAttendance z:list){
			z.setAt_amtimes(DateFormatUtil.getDateStringw(z.getAt_amtime(), "yyyy-MM-dd HH:mm:ss"));
			z.setAt_noontimes(DateFormatUtil.getDateStringw(z.getAt_noontime(), "yyyy-MM-dd HH:mm:ss"));
			z.setAt_pmtimes(DateFormatUtil.getDateStringw(z.getAt_pmtime(), "yyyy-MM-dd HH:mm:ss"));
			z.setAt_nighttimes(DateFormatUtil.getDateStringw(z.getAt_nighttime(), "yyyy-MM-dd HH:mm:ss"));
			z.setAt_days(DateFormatUtil.getDateStringw(z.getAt_day(), "yyyy-MM-dd"));
		}
		PageInfo<ZhAttendance> pageinfo = new PageInfo<ZhAttendance>(list);
		return pageinfo;
	}

	@Override
	public PageInfo<ZhAttendance> attendanceSelectByTiaojian(ZhAttendance aa) {
		if(aa.getPageNum() != null){
			PageHelper.startPage(aa.getPageNum(), 10);
		}else{
			PageHelper.startPage(1, 10);
		}
			List<ZhAttendance> list =  attendancemap.attendanceSelectByTiaojian(aa);
			for(ZhAttendance z:list){
				System.out.println(z.getAt_id());
				z.setAt_amtimes(DateFormatUtil.getDateStringw(z.getAt_amtime(), "yyyy-MM-dd HH:mm:ss"));
				z.setAt_noontimes(DateFormatUtil.getDateStringw(z.getAt_noontime(), "yyyy-MM-dd HH:mm:ss"));
				z.setAt_pmtimes(DateFormatUtil.getDateStringw(z.getAt_pmtime(), "yyyy-MM-dd HH:mm:ss"));
				z.setAt_nighttimes(DateFormatUtil.getDateStringw(z.getAt_nighttime(), "yyyy-MM-dd HH:mm:ss"));
				z.setAt_days(DateFormatUtil.getDateStringw(z.getAt_day(), "yyyy-MM-dd"));
			}
			PageInfo<ZhAttendance> pageinfo = new PageInfo<ZhAttendance>(list);
			return pageinfo;
		
		
	}

	

}
